{include file="public/header"/}
<link rel="stylesheet" href="{__PUBLIC_PATH}/admin/pcf/pcf_help.css?v={$version}"/>
<script src="{__PUBLIC_PATH}/common/js/jquery.min.js?v={$version}"></script>
<script src="{__PUBLIC_PATH}/admin/pcf/global.js?v={$version}"></script>
</head>
<body>
<div class="layui-fluid " id="LAY-component-layer-list">
<div class="layui-row layui-col-space15">
  <div class="layui-col-md12">
    <div class="layui-card">
      <div class="layui-card-body">
        <div class="layui-form house-form" lay-filter="">

        <div class="layui-form-item">
            <label class="layui-form-label">URL模式</label>
            <div class="layui-input-inline">
                {volist name="seo_pseudo_list" id="vo"}
                <input type="radio" name="seo_pseudo" lay-filter="seo_pseudo" value="{$key}" title="{$vo}" {if condition='isset($config.seo_pseudo) && $config.seo_pseudo eq $key'} checked{/if}/>
                {/volist}
            </div>
        </div>

        <div class="row {if condition='isset($config.seo_pseudo) && $config.seo_pseudo != 2'}none{/if}" id="dl_seo_html_format">
          <div class="layui-form-item ">
            <label class="layui-form-label">静态页面</label>
            <div class="layui-input-inline layadmin-layer-demo">
              <button class="layui-btn layui-btn-sm" lay-submit lay-filter="createHtml">生成静态页面</button>
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">保存目录</label>
            <div class="layui-input-inline w200">
                <input type="text" name="seo_html_arcdir" id="seo_html_arcdir" value="{$config.seo_html_arcdir|default=''}" lay-verify="check_seo_html_arcdir" placeholder="留空默认根目录" class="layui-input"> <span style="line-height:38px;margin-left:4px;">（如：html）</span>
                <div class="layui-form-inline2 {empty name='$seo_html_arcdir_1'}none{/empty}" style="color:red;" id="tips_seo_html_arcdir_1">
                    页面将保存在 {$Request.domain}<span id="tips_seo_html_arcdir_2">{$seo_html_arcdir_1|default=''}</span>/
                </div>
            </div>
            <div class="layui-input-inline layui-btn-container" style="width:auto;">
              <div class="layui-form-mid layui-word-aux ey_helptips"></div>
              <div class="layui-form-inline2 ey_helptips_txt">填写需要生成静态页面的文件夹名称，不能包含特殊字符，不能和根目录系统文件夹重名</div>
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">列表页面</label>
            <div class="layui-input-inline">
              <input type="radio" name="seo_html_listname" value="1" title="{notempty name='$root_dir'}子目录名称/{/notempty}顶级目录名称/lists_ID.html" {if condition="isset($config.seo_html_listname) && $config.seo_html_listname eq 1"} checked{/if}>
              <p class="info-text">（<a href="javascript:void(0);" onclick="view_exp('view_2_1');">查看例子</a><span id="view_2_1" class="none">：{$Request.domain}<span id="exp_seo_html_arcdir">{$seo_html_arcdir_1}</span>/news/lists_1.html</span>）</p>

              <input type="radio" name="seo_html_listname" value="2" title="{notempty name='$root_dir'}子目录名称/{/notempty}父级目录名称/子目录名称/" {if condition="!isset($config.seo_html_listname) || $config.seo_html_listname neq 1"} checked{/if}>
              <p class="info-text">（<a href="javascript:void(0);" onclick="view_exp('view_2_2');">查看例子</a><span id="view_2_2" class="none">：{$Request.domain}<span id="exp_seo_html_arcdir">{$seo_html_arcdir_1}</span>/news/dongtai/</span>）</p>
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">文档页面</label>
            <div class="layui-input-inline">
              <input type="radio" name="seo_html_pagename" value="1" title="{notempty name='$root_dir'}子目录名称/{/notempty}顶级目录名称/ID.html" {if condition="isset($config.seo_html_pagename) && $config.seo_html_pagename eq 1"} checked{/if}>
              <p class="info-text">（<a href="javascript:void(0);" onclick="view_exp('view_2_3');">查看例子</a><span id="view_2_3" class="none">：{$Request.domain}<span id="exp_seo_html_arcdir">{$seo_html_arcdir_1}</span>/news/10.html</span>）</p>

              <input type="radio" name="seo_html_pagename" value="2" title="{notempty name='$root_dir'}子目录名称/{/notempty}父级目录名称/子目录名称/ID.html" {if condition="!isset($config.seo_html_pagename) || $config.seo_html_pagename neq 1"} checked{/if}>
              <p class="info-text">（<a href="javascript:void(0);" onclick="view_exp('view_2_4');">查看例子</a><span id="view_2_4" class="none">：{$Request.domain}<span id="exp_seo_html_arcdir">{$seo_html_arcdir_1}</span>/news/dongtai/20.html</span>）</p>
            </div>
          </div>
        </div>

        <div class="layui-form-item {if condition='isset($config.seo_pseudo) && $config.seo_pseudo != 3'}none{/if}" id="dl_seo_rewrite_format">
            <label class="layui-form-label">伪静态</label>
            <div class="layui-input-inline">
              <input type="radio" name="seo_rewrite_format" value="1" title="目录名称" {if condition="!isset($config.seo_rewrite_format) OR $config.seo_rewrite_format eq 1"} checked{/if}>
              <p class="info-text">（<a href="javascript:void(0);" onclick="view_exp('view_3_1');">查看例子</a><span id="view_3_1" class="none">：{$Request.domain}/about/</span>）</p>

              <input type="radio" name="seo_rewrite_format" value="2" title="模型标识" {if condition="isset($config.seo_rewrite_format) AND $config.seo_rewrite_format eq 2"} checked{/if}>
              <p class="info-text">（<a href="javascript:void(0);" onclick="view_exp('view_3_2');">查看例子</a><span id="view_3_2" class="none">：{$Request.domain}/single/about.html</span>）</p>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">栏目页SEO</label>
            <div class="layui-input-inline">
              <input type="radio" name="seo_liststitle_format" value="1" title="栏目名称_网站名称"  {if condition="isset($config.seo_liststitle_format) AND $config.seo_liststitle_format eq 1"} checked{/if}><br>
              <input type="radio" name="seo_liststitle_format" value="2" title="栏目名称_第N页_网站名称" {if condition="!isset($config.seo_liststitle_format) OR $config.seo_liststitle_format eq 2"} checked{/if}>
            </div>
          </div>
        <div class="layui-form-item">
            <label class="layui-form-label">内容页SEO</label>
            <div class="layui-input-inline">
              <input type="radio" name="seo_viewtitle_format" value="1" title="内容标题" {if condition="isset($config.seo_viewtitle_format) AND $config.seo_viewtitle_format eq 1"} checked{/if}><br>
              <input type="radio" name="seo_viewtitle_format" value="2" title="内容标题_网站名称" {if condition="!isset($config.seo_viewtitle_format) OR $config.seo_viewtitle_format eq 2"} checked{/if}><br>
              <input type="radio" name="seo_viewtitle_format" value="3" title="内容标题_栏目名称_网站名称" {if condition="isset($config.seo_viewtitle_format) AND $config.seo_viewtitle_format eq 3"} checked{/if}>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <input type="hidden" id="seo_pseudo_old" value="{$config.seo_pseudo|default='1'}"/>
                <input type="hidden" name="seo_html_arcdir_limit" value="{$seo_html_arcdir_limit}"/>
                <input type="hidden" id="seo_inlet" value="{$config.seo_inlet}"/>
                <input type="hidden" id="init_html" value="{$init_html|default='1'}"/>
                <input type="hidden" name="seo_dynamic_format" value="1"/>
                <input type="hidden" name="inc_type" value="{$inc_type}">
                <button class="layui-btn" lay-submit lay-filter="formSubmit">确认提交</button>
            </div>
        </div>
        </div>
      </div>
    </div>
  </div>
</div>
</div>
{include file="public/footer"/}
<script>
layui.use(['layer', 'form', 'element', 'admin'], function () {
    var $ = layui.$,
    admin = layui.admin,
    element = layui.element,
    form = layui.form,
    layer = layui.layer;
    form.verify({
      check_seo_html_arcdir: function(value, item){
        if($("input[name='seo_pseudo']:checked").val() == '2'){
            var seo_html_arcdir = $('input[name="seo_html_arcdir"]').val();
            if (seo_html_arcdir != '') {
                seo_html_arcdir = seo_html_arcdir_new = seo_html_arcdir.replace('\\', '/');
                var reg = /^([0-9a-zA-Z\_\-\/]+)$/;
                if (seo_html_arcdir != '/' && reg.test(seo_html_arcdir)) {
                    // 去掉最前面的斜杆
                    if (seo_html_arcdir_new.substr(0,1) == '/') seo_html_arcdir_new = seo_html_arcdir_new.substr(1);
                    var html_arcdir_arr = seo_html_arcdir_new.split("/");
                    var html_arcdir_one = html_arcdir_arr[0]; // 一级路径名
                    var seo_html_arcdir_limit = $('input[name="seo_html_arcdir_limit"]').val();
                    var seo_html_arcdir_limit_arr = seo_html_arcdir_limit.split(",");
                    if (seo_html_arcdir_limit_arr.indexOf(html_arcdir_one) >= 0){
                        return '页面保存路径的目录名 '+html_arcdir_one+' 与内置禁用的重复!';
                    }
                }else{
                    return '页面保存路径的格式错误！';
                }
            }
        }
      }
    }); 

    // 监听URL模式
    form.on('radio(seo_pseudo)', function(data){
        var _this = data.elem;
        $('#dl_seo_html_format').hide();
        $('#dl_seo_rewrite_format').hide();
        var seo_pseudo = $(_this).val();
        if (1 == seo_pseudo) {
            if (1 != $('#seo_inlet').val()) {
                $('#dl_seo_force_inlet').show();
            } else {
                $('#dl_seo_force_inlet').hide();
            }
        } else if (2 == seo_pseudo) {
            $('#dl_seo_force_inlet').hide();
            msg = "静态模式下注意几点：<br/>1、修改模板记得生成<br/>2、更新后台数据记得生成<br/>3、安装的插件需要更新至最新版本";
            layer.alert(msg, {icon: 6, closeBtn:false, title: false});
            $('#dl_seo_html_format').show();
        } else {
            $('#dl_seo_rewrite_format').show();
            if (1 != $('#seo_inlet').val()) {
                $('#dl_seo_force_inlet').show();
            } else {
                $('#dl_seo_force_inlet').hide();
            }
        }
        var seo_pseudo_old = $('#seo_pseudo_old').val();
        if (3 == seo_pseudo) {
            layer_loading('正在检测');
            $.ajax({
                url: "{:url('/channel.Seo/ajax_checkHtmlDirpath')}",
                type: "POST",
                dataType: "json",
                data: {seo_pseudo_new:seo_pseudo},
                success: function(res){
                    layer.closeAll();
                    if (res.status) {
                        if (res.data.msg != '') {
                            $('input[name=seo_pseudo]').each(function(i,o){
                                if($(o).val() == seo_pseudo_old){
                                    $(o).attr('checked',true);
                                } else {
                                    $(o).attr('checked',false);
                                }
                            })
                            var seo_pseudo = $(_this).val();
                            var height = res.data.height + 116;
                            if (350 <= height) height = 350;
                            var confirm1 = layer.confirm(res.data.msg, {
                                    title: false,
                                    area: ['320px', height+'px'],
                                    btn: ['手工删除','自动删除']
                                }, function(){
                                    layer.close(confirm1);
                                }, function(){
                                    layer_loading('正在处理');
                                    $.ajax({
                                        url: "{:url('/channel.Seo/ajax_delHtmlDirpath')}",
                                        type: "POST",
                                        dataType: "json",
                                        success: function(res){
                                            layer.closeAll();
                                            if (res.status) {
                                                $('input[name=seo_pseudo]').each(function(i,o){
                                                    if($(o).val() == seo_pseudo){
                                                        $(o).attr('checked',true);
                                                    } else {
                                                        $(o).attr('checked',false);
                                                    }
                                                })
                                                $('#dl_seo_html_format').hide();
                                                layer.msg(res.msg, {icon: 1, time: 1500});
                                            } else {
                                                layer.msg(res.data.msg, {icon: 2, time: 1000});
                                            }
                                        },
                                        error: function(e){
                                            layer.closeAll();
                                            layer.msg("未知错误，操作中断！", {icon: 2, time: 1000});
                                        }
                                    })
                                }
                            );
                        }   
                    } else {
                        layer.msg(res.msg, {icon: 5, time: 1500});
                    }
                },
                error: function(){
                    layer.closeAll();
                    layer.msg("未知错误，操作中断！", {icon: 2, time: 1000});
                }
            });
        }  
    });

    $('#seo_html_arcdir').keyup(function(){
        var seo_html_arcdir = $(this).val();
        if (seo_html_arcdir != '') {
            if (seo_html_arcdir.substr(0,1) == '/') {
                seo_html_arcdir = seo_html_arcdir.substr(1);
            }
            seo_html_arcdir = '/' + seo_html_arcdir;
            $('#tips_seo_html_arcdir_1').show();
            $('#tips_seo_html_arcdir_2').html(seo_html_arcdir);
        } else {
            $('#tips_seo_html_arcdir_1').hide();
        }
        $('#exp_seo_html_arcdir').html(seo_html_arcdir);
    });

    //生成静态页面
    form.on('submit(createHtml)', function(data){
        $.ajax({
            url: "{:url('/channel.Seo/handle')}",
            type: 'POST',
            dataType: 'json',
            data: data.field,
            beforeSend:function(){
                layer_loading('保存配置');
            },
            success: function(res){
                layer.closeAll();
                if (res.status) {
                    var iframes = layer.open({
                        type: 2,
                        title: '生成静态页面',
                        fixed: true,
                        shadeClose: false,
                        shade: 0.3,
                        content: "{:url('/channel.Seo/index',['inc_type'=>'html'])}"
                    });
                    layer.full(iframes);  
                } else {
                   layer.msg("生成失败！", {icon: 2, time: 1000});
                }
            },
            error: function(e){
                layer.closeAll();
                layer.msg("生成失败，请先提交保存配置！", {icon: 2, time: 1000});
            }
        });
    })

    //监听提交
    form.on('submit(formSubmit)', function(data){
        layer.load(2);
        var init_html = $('#init_html').val();
        $.ajax({
            type : 'post',
            url : "{:url('/channel.Seo/handle')}",
            data : data.field,
            dataType : 'json',
            success : function(res){
                if (res.status) 
                {
                    if (2 == init_html || 2 != $("input[name='seo_pseudo']:checked").val()) {
                        layer.msg(res.msg, {icon: 1, time: 1000}, function(){
                            window.location.href = res.url;
                        });
                    } else {
                        layer.closeAll('loading');
                        var confirm1 = layer.confirm('配置成功，是否要生成整站页面？', {
                                title: false,
                                closeBtn: false,
                                btn: ['是','否']
                            }, function(){
                                var url = "{:url('/channel.Seo/site')}";
                                var index = layer.open({
                                    type: 2,
                                    title: '开始生成',
                                    area: ['500px', '300px'],
                                    fix: false, 
                                    maxmin: false,
                                    content: url,
                                    end: function(layero, index){
                                        layer.msg(res.msg, {icon: 1, time: 1000}, function(){
                                            window.location.href = res.url;
                                        });
                                    }
                                });
                            }, function(){
                                layer.msg(res.msg, {icon: 1, time: 1000}, function(){
                                    window.location.href = res.url;
                                });
                            }
                        );
                    }
                } else {
                    layer.closeAll('loading');
                    layer.msg(res.msg, {icon: 2, time: 1000});
                }
            },
            error: function(e){
                layer.closeAll('loading');
                layer.msg("未知错误，操作中断！", {icon: 2, time: 1000});
            }
        });
        return false;
    });

});

function view_exp(id){
    $('#'+id).toggle();
}

</script>
</body>
</html>